/*
Master file for the PPP data analysis that lists all STATA code used for this project in order.

SQL code (using confidential data and variables) was used in preliminary data creation steps and that is noted in this file where pertinent
*/

/////////////////////////////////
//// Code for cleaning and preparing data
/////////////////////////////////

//Read in the global variables
do "ppp/do/make_globals.do"

//Prepare PPP data for matching to the tax data on the CDW and for other analyses
do "$dodir/cleaning/import_ppp.do"

/*
SQL code is used to produce matches between the PPP data from SBA and the tax data from CDW
*/

//Read in and combine all PPP matches from the CDW
do "$dodir/cleaning/import_matches.do"

/*
SQL code was used to pull quarterly form 941 data
*/

//Read in 941 data, combine with PPP data and reformat tax and PPP data for use in regressions and distributional analysis
do "$dodir/cleaning/import_from_cdw.do"

/*
SQL code is used to produce distributions of wages paid by firms, UI paid to employees of firms and ownership of firms. Tax rates were also calculated in SQL.
*/

//Read in distributional data and combine with PPP data
do "$dodir/cleaning/distributional_data.do"

//Final preparations of data for regressions
do "$dodir/analysis/reg_data.do"

//////////////////////////////////
///// Regression analysis code
//////////////////////////////////

//Perform the main regression analysis (Figure 2,A6 and Table 1)
do "$dodir/analysis/f941_cells_regs.do"

//Put together main regression results table (Table 1)
do "$dodir/analysis/wage_table.do"

//Perform the regression analysis for restaurants (Figure A5)
do "$dodir/analysis/f941_restaurant_regs.do"

//Perform the regression analysis using never-treated as control (Figure A7)
do "$dodir/analysis/f941_nopp_regs.do"

//Perform the regression analysis for New York and New Jersey separately (Figure A8)
do "$dodir/analysis/f941_regs_nynj.do"

//Perform the regression analysis for comparison with Autor et al. 
do "$dodir/analysis/f941_cells_regs_autor.do"


///////////////////////////////////////////////////
///// Various Summary Statistics, Tables and Figures
///////////////////////////////////////////////////

// PPP loan only statistics
do "$dodir/analysis/ppp_tabs.do"

// Statistics on owners and scale up factors
do "$dodir/analysis/sum_stats_owner_match.do"

// Statistics on form 941 and scale-up factors (Figure A2,A4 and A9)
do "$dodir/analysis/summarize_941_matches.do"

// Summarize all matches (Tables A1 and A2)
do "$dodir/analysis/summarize_matches.do"

// Summarize W-2 matches and scale up factors
do "$dodir/analysis/summarize_w2_matches.do"

// Produce figure on uptake rates by firm size (Figure A1)
do "$dodir/analysis/threshold_500_line_plot.do"

//Comparing SBA loan amounts and amounts inferred from passthrough Schedule K returns (Figure A2)
do "$dodir/analysis/sba_schk.do"

//////////////////////////////////
///// Distributional analysis code
//////////////////////////////////

// Perform the UI analysis (Figure 4,A10)
do "$dodir/analysis/explore_ui.do"

// Output the distributional estimates(Figure 3,4 and A3,A10)
do "$dodir/analysis/distribution_and_tax.do"
